package Service;

import Dao.UserByPageDao;
import Table.PageBean;
import Table.User;

import java.util.ArrayList;

public class UserByPageService {
    public static PageBean<User> FindUser(String currentPage, String rows) {
        int rows1 = Integer.parseInt(rows);
        int currentPage1 = Integer.parseInt(currentPage);
        PageBean<User> pageBean = new PageBean<>();
        pageBean.setCurrentPage(currentPage1);
        pageBean.setRows(rows1);
        int totalCount = UserByPageDao.FindTotalCount();
        pageBean.setTotalCount(totalCount);

        int start = (currentPage1 - 1) * rows1;
        ArrayList<User> list = UserByPageDao.FindByPage(start, rows1);
        pageBean.setList(list);

        int totalPage = (totalCount % rows1) == 0 ? totalCount / rows1 : (totalCount / rows1) + 1;
        pageBean.setTotalPage(totalPage);
        return pageBean;

    }
}
